#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:pengfeifu
@file: day_14_re.py 
@version:
@time: 2021/11/04 
@email:1324734112@qq.com
@desc：正则表达式模块
@function:
findall	返回包含所有匹配项的<列表>
search	如果字符串中的任意位置存在匹配，则返回 Match 对象
split	返回在每次匹配时拆分字符串的列表,split的参数用maxsplit控制切割次数，比如maxsplit=1，仅仅以第一次为分隔符
sub	用字符串替换一个或多个匹配项，类似replace功能
"""

import re

str = "China is a great country"
space_list = re.findall("\s", str)
print(type(space_list))
print(space_list)
print("以上findall方法：" + "*" * 150)
match_search = re.search("\s", str)
print(type(match_search))
print(match_search)
print(match_search.start())
print(match_search.end())
print(dir(match_search))
print("以上search方法：" + "*" * 150)
str_list = re.split("\s", str)
print(type(str_list))
print(str_list)
city_str_list = re.split("\s", str, maxsplit=1)
print(city_str_list)
print("以上split方法：" + "*" * 150)
sub_str = re.sub("\s", "$", str)
print(sub_str)
